<!doctype html>
<html>
<head>
<meta charset="utf-8">
    <title>申请区域代理商</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">     
    <meta content="yes" name="apple-mobile-web-app-capable">     
    <meta content="black" name="apple-mobile-web-app-status-bar-style">     
    <meta content="telephone=no" name="format-detection">
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" type="text/css" href="/H5/css/sm.min.css" />
    <link rel="stylesheet" type="text/css" href="/H5/css/City.css" />
    <link rel="stylesheet" type="text/css" href="/H5/css/reset.css?v=1" />
</head>               
<body>
	<div class="page-group ms-controller" :controller="memberAgent">
        <div class="page page-current" style="background: #efeff4">
            <header class="bar bar-nav">
              	<a class="icon icon-left pull-left" href="javascript:window.history.go(-1);"></a>
              	<a class="icon icon-home pull-right" href="/H5"></a>
              	<h1 class="title">申请区域代理商</h1>
            </header>
            <div class="content visibility">
            	<div class="content-block-title title01">温馨提示：请认真填写以下信息！</div>
            	  	<div class="list-block" style="margin:0">
	            	    <ul class="block-ul">
	            	      	
	            	      	<li>
	            	        	<div class="item-content">
	            	          		<div class="item-inner">
	            	            		<div class="item-title label"><span style="color:red; margin-right:2%;"></span>代理级别</div>
	            	            		<div class="item-input">
	            	                		<input type="text" id="level" readonly placeholder="请选择代理级别">
	            	                		<input type="hidden" :duplex="level" id="levelValue" readonly>
	            	            		</div>
	            	          		</div>
	            	        	</div>
	            	      	</li>
	            	      	
	            	      	<!-- <li>
		            	        <div class="item-content">
			            	        <div class="item-inner">
			            	            <div class="item-title label"><span style="color:red; margin-right:2%;">*</span>推荐人号码</div>
			            	            <div class="item-input">
			            	              <input type="text" :attr="{'readonly': @referee_only?true:false}" :duplex="referee" placeholder="请填写推荐人手机号">
			            	            </div>
			            	        </div>
		            	        </div>
		            	    </li> -->
		            	    
		            	    <li>
		            	        <div class="item-content">
			            	        <div class="item-inner">
			            	            <div class="item-title label"><span style="color:red; margin-right:2%;"></span>营业执照</div>
			            	            <div class="item-input">
			            	                <input type="file" :on-change="@upload" id="file" name="kcs_uploader_file" accept="image/*"/>
			            	            </div>
			            	        </div>
		            	        </div>
		            	    </li>
		            	    <li>
		            	        <div class="item-content">
			            	        <div class="item-inner">
			            	            <div class="item-title label"><span style="color:red; margin-right:2%;"></span>公司名称</div>
			            	            <div class="item-input">
			            	              <input type="text" :attr="{'readonly': @company_only?false:false}" :duplex="company" placeholder="请填写公司名称">
			            	            </div>
			            	        </div>
		            	        </div>
		            	    </li>
		            	    
		            	    
		            	    <li>
		            	        <div class="item-content">
			            	        <div class="item-inner">
			            	            <div class="item-title label"><span style="color:red; margin-right:2%;"></span>申请地区</div>
			            	            <div class="item-input">
			            	            	<input type="text" id="picker" readonly placeholder="请选择地区">
			            	            	<input type="hidden" :duplex="location" id="value">
			            	            </div>
			            	        </div>
		            	        </div>
		            	    </li>
		            	    
		            	    
		            	    
		            	    <li>
	            	        	<div class="item-content">
	            	          		<div class="item-inner">
	            	            		<div class="item-title label"><span style="color:red; margin-right:2%;">*</span>申请进度</div>
	            	            		<div class="item-input">
	            	                		<input type="text" id="check_status_label" :duplex="check_status_label" name="check_status_label" readonly>
	            	                		
	            	            		</div>
	            	          		</div>
	            	        	</div>
	            	      	</li>
		            	    <li>
		            	        <div class="item-content" style="background-color:#fcfcfc;">
			            	        <div class="item-inner">
			            	            <span style="color:red; margin:0 5% 0 12%;"><input type="checkbox"  name="one" /></span>
			            	            <div class="item-input" style="font-size:16px; color:#666;">
			            	                同意<a href="privacyStatement">《会员信息隐私声明》</a>
			            	            </div>
			            	        </div>
		            	        </div>
		            	    </li>
	            	  	</ul>    
		            	<div class="content-block">
			            	<div class="row">
			            	      	<div class="col-50" style="width:95%;"><a href="javascript:;" :on-click="@submit" class="button button-big button-fill button-danger" id="sure">确认并提交</a></div>
			            	</div>
		            	</div>
	            	</div>
            	</div>
            </div>
        </div>
    </div>
<script type='text/javascript' src='/H5/js/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/avalon.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/simpleStorage.js' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/mall.js?v=10' charset='utf-8'></script>
<script type='text/javascript' src='/H5/js/City.js' charset='utf-8'></script>
<script>
	var memberAgent = avalon.define({
		$id: "memberAgent",
		level: "1",
		level_only: false,
		business_licence: "",
		company: "",
		company_only: false,
		referee: "",
		referee_only: false,
		location: "",
		check_status_label:"",
		status:"",
		status_only: false,
		info: {},
		getInfo: function(){
			Mall.request( "/api/GetAgent" )
				.always( function( data ){
					if( data.error_code == 0 ){
					    memberAgent.info = data.data;
					    memberAgent.level = data.data.level?data.data.level:'';
				    	memberAgent.company = data.data.company?data.data.company:'';
				    	data.data.company && ( memberAgent.company_only = true );
				    	memberAgent.referee = data.data.referee?data.data.referee:'';
				    	data.data.referee && ( memberAgent.referee_only = true );
				    	memberAgent.location = data.data.location;
				    	memberAgent.check_status_label = data.data.check_status_label?data.data.check_status_label:'未申请';
					    if( data.data.location_label ){
					    	$( "#picker" ).val( data.data.location_label );
					    	memberAgent.getCity();
					    }
					    else{
					    	memberAgent.getCity();
					    }
					    if(data.data.check_status==0||data.data.check_status==1){
                            $( "#sure" ).addClass( "visibility" )
						}else{
                            $( "#sure" ).removeClass( "visibility" )
						}
					    data.data.level && ( memberAgent.level = data.data.level );
					    data.data.level_label && $( "#level" ).val( data.data.level_label );
					    
					    $("#level").picker({
					      	toolbarTemplate: '<header class="bar bar-nav">\
					      		<button class="button button-link pull-right close-picker">确定</button>\
					      		<h1 class="title">请选择代理级别</h1>\
					      		</header>',
					      	cols: [{textAlign: 'center',values: ['0', '1'],displayValues: ["县级代理","市级代理"]}],
					      	formatValue: function( e, v ,dv ){
					      		$( "#levelValue" ).val( v )
					      		return dv
					      	}
					    });
                        $( ".content" ).removeClass( "visibility" );
					}
				} )
		},
		getCity: function(){
		    Mall.request("/api/AreaDict")
		        .always( function( data ){
		            if( data.error_code == 0 ){
		                var location = new LArea();
		                location.init({
		                    'trigger': '#picker', //触发选择控件的文本框，同时选择完毕后name属性输出到该位置
		                    'valueTo': '#value', //选择完毕后id属性输出到该位置
		                    'keys': {
		                        id: 'id',
		                        name: 'name'
		                    }, //绑定数据源相关字段 id对应valueTo的value属性输出 name对应trigger的value属性输出
		                    'type': 1, //数据源类型
		                    'data': data.data //数据源
		                });
		            }
		        } )
		},
		
		submit: function(){
			if( Mall.LOCK ){
				return
			}
			if(!$("input[name=one]").is(':checked')){
				$.toast( "请同意声明", 2000, "warning" )
				return
			}
			Mall.LOCK = true;
			var postData = {
			}
			memberAgent.company && ( postData.company = memberAgent.company );
			memberAgent.location && ( postData.location = memberAgent.location );
			memberAgent.level && ( postData.level = memberAgent.level );
			//memberAgent.dateTime && ( postData.born = memberAgent.dateTime );
			memberAgent.business_licence && ( postData.business_licence = memberAgent.business_licence );
			Mall.request( "/api/memberAgent", postData )
				.always( function( data ){
					if( data.error_code == 0 ){
					    $.toast( "申请区域代理成功", 1000, "success", function(){
					        window.location.href="/H5/member";
					    } )
					}
					Mall.LOCK = false;
				} )
		},
		upload: function(){
			if( $('#file')[0].files[0].size > 2*1024*1024 ){
				$.toast( "图片不能超过2M", 1000, "warning" )
				return
			}
			$.showPreloader( "图片上传中" );
		    var formData = new FormData();
		    formData.append('kcs_uploader_file', $('#file')[0].files[0]);
		    formData.append('api_token', simpleStorage.get( "token" ));
		    $.ajax({
                url : ( simpleStorage.get( "host" ) || "http://"+location.hostname ) + '/api/Upload',//这里写你的url
                type : 'POST',
                data : formData,
                contentType: false,// 当有文件要上传时，此项是必须的，否则后台无法识别文件流的起始位置
                processData: false,// 是否序列化data属性，默认true(注意：false时type必须是post)
                dataType: 'json',//这里是返回类型，一般是json,text等
                clearForm: true,//提交后是否清空表单数据
                success: function(data) {   //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
                    memberAgent.business_licence = data.data.avatar_url;
                    $.toast( "营业执照上传成功", 1000, "success", function(){
                    	$.hidePreloader();
                    } )

                },
                error: function(data, status, e) {  //提交失败自动执行的处理函数。
                    $.alert(e);
                    $.hidePreloader();
                }
            });
		},
	})
	memberAgent.getInfo();
	avalon.scan( document.body )
</script>
</body>
</html>
